package com.xuly.dao;

import com.xuly.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface StudentDao extends JpaRepository<Student, Long> {

    @Query("select s from Student s where s.stuName like ?1%")
    List<Student> findByNameLikeUseIndex(String name);

    @Query("select s from Student s where s.stuName like %?1%")
    List<Student> findByNameLike(String name);

    @Query("select s from Student s where s.stuName like ?1% and s.stuNum = ?2")
    List<Student> findByComboLikeUseIndex(String name, int num);

    @Query("select s from Student s where s.stuName like %?1% and s.stuNum = ?2")
    List<Student> findByComboLike(String name, int num);

    @Modifying
    @Query("update Student s set s.createDate=:date where s.stuName like :name%")
    int updateStuByLikeName(@Param("name") String name, @Param("date") Date createDate);

}
